package com.zhentao.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Date 2024/4/1 14:53
 * @Author xdm
 **/
@RestController
@RequestMapping("/sent")
public class SentinelController {

    @GetMapping("/exNum")
    public String exNum(int a){
        if(a==1) {
            int i = 1 / 0;
        }
        return "异常数";
    }

    @RequestMapping("/slowNum")
    public String slowNum(int a){
        if(a==1){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        return "慢调用";
    }

    @GetMapping("/select/{id}")
    @SentinelResource("selectById")
    public String selectById(@PathVariable("id")  String id){
        System.out.println(id);
        return "热点规则："+id;
    }

}
